package com.ruoyi.order.enums;

import com.ruoyi.common.exception.ServiceException;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单状态:1:未付款；2：已付款；3：已完工;4.已取消
 */
public enum OrderStatusAppEnum {

    WAIT_PAY(1, "待付款"),
    PAID(2, "已报名"),
    FINISH(3, "已完工"),
    CANCEL_ORDER(4, "已取消"),

    ;
    private Integer code;
    private String description;

    private static List<OrderStatusAppEnum> statusEnumList = new ArrayList<>();

    static {
        statusEnumList.add(WAIT_PAY);
        statusEnumList.add(PAID);
        statusEnumList.add(FINISH);
        statusEnumList.add(CANCEL_ORDER);
    }

    OrderStatusAppEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static OrderStatusAppEnum getOrderStatusEnumByCode(Integer code) {
        switch (code) {
            case 1:
                return WAIT_PAY;
            case 2:
                return PAID;
            case 3:
                return FINISH;
            case 4:
                return CANCEL_ORDER;
            default:
                throw new ServiceException("错误订单状态类型");
        }
    }

    /**
     * 是否合法
     *
     * @param code
     * @return
     */
    public static Boolean isExist(Integer code) {
        OrderStatusAppEnum statusEnum = getOrderStatusEnumByCode(code);
        return statusEnumList.contains(statusEnum);
    }

}
